package wiki.old.cs236703.Wiki.Implementation;

import java.util.HashSet;
import java.util.Set;

import wiki.old.cs236703.Wiki.ContentRanker;
import wiki.old.cs236703.Wiki.PatternType;
import wiki.old.cs236703.Wiki.ContentType;


public class SimpleContentRanker implements ContentRanker {
	Set<String> neutralWords = new HashSet<String>(); 
	PatternType p = null;	
	
	@Override
	public void addNeutralWord(String w) {
		neutralWords.add(w);
	}

	@Override
	public void removeNeutralWord(String w) {
		neutralWords.remove(w);
	}

	@Override
	public String[] getNeutralWords() {
		return neutralWords.toArray(new String[0]);
	}

	public ContentType getHandledContentType() {
		return ContentType.HTML;
	}

	@Override
	public void setQuery(String query) throws QueryException {
		for (QueryType type: QueryType.values()){
			if (type.canParseQuery(query))
				p = type.generateQuery(query);
		}
		if (p == null)
			throw new QueryException();			
	}

	@Override
	public int rank(byte[] content) {
		return p.matchScore(new String(content));
	}	
}
